package com.honglang.module.album.service;

import java.util.Collection;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.honglang.module.album.dao.AlbumPhotoDao;
import com.honglang.module.album.entity.AlbumPhoto;

public class AlbumPhotoServiceImpl implements AlbumPhotoService {
	
	private AlbumPhotoDao albumPhotoDao;

	
	
	
	/**
	 * get albumphoto entities by photo;
	 * @param photoId
	 * @return
	 */
	public List<AlbumPhoto> getAlbumPhotoByPhotoId(Integer photoId){
		
		DetachedCriteria dc = DetachedCriteria.forClass(AlbumPhoto.class);
		dc.add(Restrictions.eq("photo.id", photoId));
		return this.getAlbumPhotoDao().getByDetachedCriteria(dc);
	}
	
	
	/**
	 * get albumphoto entities by album;
	 * @param albumId
	 * @return
	 */
	public List<AlbumPhoto> getAlbumPhotoByAlbumId(Integer albumId){
		
		DetachedCriteria dc = DetachedCriteria.forClass(AlbumPhoto.class);
		dc.add(Restrictions.eq("album.id", albumId));
		return this.getAlbumPhotoDao().getByDetachedCriteria(dc);
	}
	
	
	/**
	 * get a list of albumphoto  entities by album;
	 * @param albumId
	 * @return
	 */
	public List<AlbumPhoto> getAlbumPhotoByAlbumIdList(List<Integer> albumIdList){
		
		DetachedCriteria dc = DetachedCriteria.forClass(AlbumPhoto.class);
		dc.add(Restrictions.in("album.id", albumIdList));
		return this.getAlbumPhotoDao().getByDetachedCriteria(dc);
	}
	
	
	/**
	 * delete all the ablumphotos;
	 * @param ablumPhotoColl
	 */
	public void delete(Collection<AlbumPhoto> ablumPhotoColl){
		this.getAlbumPhotoDao().deleteAll(ablumPhotoColl);
	}
	
	/**
	 * delete albumPhoto
	 * @param albumPhoto
	 */
	public void delete(AlbumPhoto albumPhoto){
		this.getAlbumPhotoDao().delete(albumPhoto);
	}
	
	
	/**
	 * save a albumPhoto
	 * @param albumPhoto
	 * @return
	 */
	public AlbumPhoto save(AlbumPhoto  albumPhoto){
		
		return this.getAlbumPhotoDao().merge(albumPhoto);
	}
	
	
	
	
	/**
	 * batch save albumPhoto
	 * @param albumPhotoList
	 */
	public void save(List<AlbumPhoto> albumPhotoList){
		
		this.getAlbumPhotoDao().batchSaveOrUpdate(albumPhotoList);
	}
	
	
	
	/**
	 * get albumPhoto by Id
	 * @param albumPhotoId
	 * @return
	 */
	public AlbumPhoto getById(Integer albumPhotoId){
		return this.getAlbumPhotoDao().getById(albumPhotoId);
	}
	
	
	
	public AlbumPhotoDao getAlbumPhotoDao() {
		return albumPhotoDao;
	}

	public void setAlbumPhotoDao(AlbumPhotoDao albumPhotoDao) {
		this.albumPhotoDao = albumPhotoDao;
	}
}
